import { Component, OnInit } from '@angular/core';
import {ExtendHttpService} from "../../../common/extend-http.service";
import {TipService} from "../../services/tip.service";
import {ActivatedRoute, Router} from "@angular/router";

@Component({
  selector: 'app-order-record',
  templateUrl: './order-record.component.html',
  styleUrls: ['./order-record.component.css']
})
export class OrderRecordComponent implements OnInit {

  logList = [];
  orderId = '';
  tid = '';
  tipType = 'error';
  constructor(
    private extendHttp: ExtendHttpService,
    private tipService: TipService,
    private activatedRoute: ActivatedRoute,
    private router: Router
  ) {
    this.activatedRoute.queryParams.subscribe(param=> {
      this.orderId = param['orderId'];
      this.tid = param['tid'];
    });
  }

  ngOnInit() {
    cBack =()=> {
      $('#btn-back').trigger('click');
    }
    this.extendHttp.post('/merchantApp/singleprocess/findOperation', {orderId: this.orderId}).subscribe(response => {
      let data = response.json();
      if (data.code == '0') {
        data.orderLogList.forEach(v=>{
          let str = v.content;
          str = str.substr(0,2);
          v.stateStr = str;
        });
        this.logList = data['orderLogList'];
      } else if (data.code == '-2001') {
        this.tipType = 'error';
        this.tipService.change(true, '登录超时，跳转到登录页面');
        setTimeout(()=> {
          this.router.navigate(['/login']);
        }, 2000);
      } else {
        this.tipType = 'error';
        this.tipService.change(true, data.message);
      }
    }, error => {
      this.tipType = 'error';
      this.tipService.change(true, '系统繁忙，操作失败！');
    });
  }

}
